VERSION 5.00
Begin VB.Form frmUpdateCustomer 
   Caption         =   "עדכון לקוח"
   ClientHeight    =   8490
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   8940
   LinkTopic       =   "Form1"
   ScaleHeight     =   8490
   ScaleWidth      =   8940
   StartUpPosition =   3  'Windows Default
   Begin VB.ComboBox lstPriceListNum 
      Height          =   315
      ItemData        =   "frmUpdateCustomer.frx":0000
      Left            =   4200
      List            =   "frmUpdateCustomer.frx":0002
      TabIndex        =   52
      Top             =   7440
      Width           =   2655
   End
   Begin VB.TextBox txtCharge 
      Alignment       =   1  'Right Justify
      Height          =   285
      Left            =   4200
      MultiLine       =   -1  'True
      TabIndex        =   48
      Top             =   7080
      Width           =   1095
   End
   Begin VB.ComboBox lstCurrency 
      Height          =   315
      ItemData        =   "frmUpdateCustomer.frx":0004
      Left            =   2760
      List            =   "frmUpdateCustomer.frx":0017
      TabIndex        =   47
      Top             =   7080
      Width           =   735
   End
   Begin VB.ComboBox lstBanks 
      Height          =   315
      ItemData        =   "frmUpdateCustomer.frx":0034
      Left            =   2040
      List            =   "frmUpdateCustomer.frx":0056
      TabIndex        =   45
      Top             =   6120
      Width           =   1695
   End
   Begin VB.TextBox txtBankBranch 
      Alignment       =   1  'Right Justify
      Height          =   285
      Left            =   4440
      TabIndex        =   43
      Top             =   6120
      Width           =   615
   End
   Begin VB.TextBox txtAccountNumber 
      Alignment       =   1  'Right Justify
      Height          =   285
      Left            =   5640
      TabIndex        =   41
      Top             =   6120
      Width           =   1695
   End
   Begin VB.TextBox txtCustomerBalance 
      Alignment       =   1  'Right Justify
      Enabled         =   0   'False
      Height          =   285
      Left            =   5760
      TabIndex        =   38
      Top             =   6720
      Width           =   1575
   End
   Begin VB.TextBox txtForeignKey 
      Alignment       =   1  'Right Justify
      Enabled         =   0   'False
      Height          =   285
      Left            =   5760
      TabIndex        =   36
      Top             =   7920
      Width           =   1575
   End
   Begin VB.ComboBox lstCustomers 
      Height          =   315
      Left            =   4320
      TabIndex        =   34
      Top             =   1200
      Width           =   3135
   End
   Begin VB.TextBox txtBusinessName 
      Alignment       =   1  'Right Justify
      Height          =   285
      Left            =   5760
      TabIndex        =   0
      Top             =   2040
      Width           =   1575
   End
   Begin VB.CommandButton cmdCancel 
      Caption         =   "ביטול"
      Height          =   375
      Left            =   480
      TabIndex        =   16
      Top             =   8040
      Width           =   735
   End
   Begin VB.CommandButton cmdOK 
      Caption         =   "OK"
      Height          =   375
      Left            =   1320
      TabIndex        =   15
      Top             =   8040
      Width           =   1095
   End
   Begin VB.TextBox txtOsekMorshe 
      Alignment       =   1  'Right Justify
      Height          =   285
      Left            =   2400
      TabIndex        =   1
      Top             =   2040
      Width           =   1935
   End
   Begin VB.TextBox txtAddress1 
      Alignment       =   1  'Right Justify
      Height          =   285
      Left            =   4320
      TabIndex        =   2
      Top             =   2520
      Width           =   3015
   End
   Begin VB.TextBox txtAddress2 
      Alignment       =   1  'Right Justify
      Height          =   285
      Left            =   4320
      TabIndex        =   13
      Top             =   2880
      Width           =   3015
   End
   Begin VB.TextBox txtCity 
      Alignment       =   1  'Right Justify
      Height          =   285
      Left            =   6120
      TabIndex        =   3
      Top             =   3360
      Width           =   1215
   End
   Begin VB.TextBox txtPostalCode 
      Alignment       =   1  'Right Justify
      Height          =   285
      Left            =   4320
      TabIndex        =   4
      Top             =   3360
      Width           =   1095
   End
   Begin VB.TextBox txtContactFirstName 
      Alignment       =   1  'Right Justify
      Height          =   285
      Left            =   5520
      TabIndex        =   5
      Top             =   4200
      Width           =   1815
   End
   Begin VB.TextBox txtContactLastName 
      Alignment       =   1  'Right Justify
      Height          =   285
      Left            =   2400
      TabIndex        =   6
      Top             =   4200
      Width           =   1695
   End
   Begin VB.TextBox txtEMail 
      Alignment       =   1  'Right Justify
      Height          =   285
      Left            =   4320
      TabIndex        =   7
      Top             =   4560
      Width           =   3015
   End
   Begin VB.TextBox txtPhone1 
      Alignment       =   1  'Right Justify
      Height          =   285
      Left            =   5640
      TabIndex        =   8
      Top             =   5040
      Width           =   1695
   End
   Begin VB.TextBox txtPhone2 
      Alignment       =   1  'Right Justify
      Height          =   285
      Left            =   3000
      TabIndex        =   9
      Top             =   5040
      Width           =   1695
   End
   Begin VB.TextBox txtFax 
      Alignment       =   1  'Right Justify
      Height          =   285
      Left            =   480
      TabIndex        =   10
      Top             =   5040
      Width           =   1935
   End
   Begin VB.ComboBox lstExpMonth 
      Height          =   315
      ItemData        =   "frmUpdateCustomer.frx":00CB
      Left            =   1920
      List            =   "frmUpdateCustomer.frx":00F3
      TabIndex        =   12
      Top             =   5520
      Width           =   855
   End
   Begin VB.ComboBox lstExpYear 
      Height          =   315
      ItemData        =   "frmUpdateCustomer.frx":0127
      Left            =   3000
      List            =   "frmUpdateCustomer.frx":0140
      TabIndex        =   14
      Top             =   5520
      Width           =   975
   End
   Begin VB.TextBox txtCreditCard 
      Alignment       =   1  'Right Justify
      Height          =   285
      Left            =   5400
      TabIndex        =   11
      Top             =   5520
      Width           =   1935
   End
   Begin VB.Line Line8 
      X1              =   240
      X2              =   8760
      Y1              =   3720
      Y2              =   3720
   End
   Begin VB.Line Line7 
      X1              =   8760
      X2              =   8760
      Y1              =   2400
      Y2              =   3720
   End
   Begin VB.Line Line6 
      X1              =   240
      X2              =   240
      Y1              =   2400
      Y2              =   3720
   End
   Begin VB.Line Line5 
      X1              =   240
      X2              =   8760
      Y1              =   2400
      Y2              =   2400
   End
   Begin VB.Line Line4 
      X1              =   8760
      X2              =   8760
      Y1              =   3840
      Y2              =   6480
   End
   Begin VB.Line Line3 
      X1              =   240
      X2              =   8760
      Y1              =   3840
      Y2              =   3840
   End
   Begin VB.Line Line2 
      X1              =   240
      X2              =   8760
      Y1              =   6480
      Y2              =   6480
   End
   Begin VB.Line Line1 
      X1              =   240
      X2              =   240
      Y1              =   3840
      Y2              =   6480
   End
   Begin VB.Label Label27 
      Alignment       =   1  'Right Justify
      Caption         =   "מחירון (כספית+מלאי):"
      Height          =   255
      Left            =   6960
      TabIndex        =   51
      Top             =   7440
      Width           =   1695
   End
   Begin VB.Label Label25 
      Alignment       =   1  'Right Justify
      Caption         =   "מחיר לשעת עבודה (עבור כספית+יועצים):"
      Height          =   255
      Left            =   5520
      TabIndex        =   50
      Top             =   7080
      Width           =   3135
   End
   Begin VB.Label Label26 
      Alignment       =   1  'Right Justify
      Caption         =   "מטבע:"
      Height          =   255
      Left            =   3360
      TabIndex        =   49
      Top             =   7080
      Width           =   735
   End
   Begin VB.Label Label24 
      Alignment       =   1  'Right Justify
      Caption         =   "בנק:"
      Height          =   255
      Left            =   3480
      TabIndex        =   46
      Top             =   6120
      Width           =   735
   End
   Begin VB.Label Label23 
      Alignment       =   1  'Right Justify
      Caption         =   "סניף:"
      Height          =   255
      Left            =   4800
      TabIndex        =   44
      Top             =   6120
      Width           =   735
   End
   Begin VB.Label Label22 
      Alignment       =   1  'Right Justify
      Caption         =   "מספר חשבון:"
      Height          =   255
      Left            =   7440
      TabIndex        =   42
      Top             =   6120
      Width           =   1215
   End
   Begin VB.Label Label21 
      Alignment       =   1  'Right Justify
      Caption         =   "הטופס מדגים: שליפה של לקוחות, עדכון לקוח לפי מפתח זר, שליפה של יתרת לקוח."
      Height          =   375
      Left            =   2160
      TabIndex        =   40
      Top             =   600
      Width           =   6495
   End
   Begin VB.Label Label20 
      Alignment       =   1  'Right Justify
      Caption         =   "יתרת לקוח:"
      Height          =   255
      Left            =   7440
      TabIndex        =   39
      Top             =   6720
      Width           =   1215
   End
   Begin VB.Label Label19 
      Alignment       =   1  'Right Justify
      Caption         =   "מפתח זר:"
      Height          =   255
      Left            =   7440
      TabIndex        =   37
      Top             =   7920
      Width           =   1215
   End
   Begin VB.Label Label18 
      Alignment       =   1  'Right Justify
      Caption         =   "2. לאחר שבחרת בלקוח עדכן את הפרטים ולחץ על OK:"
      Height          =   255
      Left            =   4320
      TabIndex        =   35
      Top             =   1680
      Width           =   4335
   End
   Begin VB.Label Label17 
      Alignment       =   1  'Right Justify
      Caption         =   "1. בחר בלקוח:"
      Height          =   255
      Left            =   7560
      TabIndex        =   33
      Top             =   1200
      Width           =   1095
   End
   Begin VB.Label Label1 
      Alignment       =   1  'Right Justify
      Caption         =   "טופס עדכון לקוח לפי מפתח זר"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   177
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   4680
      TabIndex        =   32
      Top             =   120
      Width           =   3975
   End
   Begin VB.Label Label2 
      Alignment       =   1  'Right Justify
      Caption         =   "שם העסק:"
      Height          =   255
      Left            =   7680
      TabIndex        =   31
      Top             =   2040
      Width           =   975
   End
   Begin VB.Label Label3 
      Alignment       =   1  'Right Justify
      Caption         =   "מספר ע""מ:"
      Height          =   255
      Left            =   4680
      TabIndex        =   30
      Top             =   2040
      Width           =   975
   End
   Begin VB.Label Label4 
      Alignment       =   1  'Right Justify
      Caption         =   "כתובת 1:"
      Height          =   255
      Left            =   7680
      TabIndex        =   29
      Top             =   2520
      Width           =   975
   End
   Begin VB.Label Label5 
      Alignment       =   1  'Right Justify
      Caption         =   "כתובת 2:"
      Height          =   255
      Left            =   7680
      TabIndex        =   28
      Top             =   2880
      Width           =   975
   End
   Begin VB.Label Label6 
      Alignment       =   1  'Right Justify
      Caption         =   "עיר:"
      Height          =   255
      Left            =   7680
      TabIndex        =   27
      Top             =   3360
      Width           =   975
   End
   Begin VB.Label Label7 
      Alignment       =   1  'Right Justify
      Caption         =   "מיקוד:"
      Height          =   255
      Left            =   5520
      TabIndex        =   26
      Top             =   3360
      Width           =   495
   End
   Begin VB.Label Label8 
      Alignment       =   1  'Right Justify
      Caption         =   "שם פרטי:"
      Height          =   375
      Left            =   7440
      TabIndex        =   25
      Top             =   4200
      Width           =   1215
   End
   Begin VB.Label Label9 
      Alignment       =   1  'Right Justify
      Caption         =   "שם משפחה:"
      Height          =   255
      Left            =   3840
      TabIndex        =   24
      Top             =   4200
      Width           =   1215
   End
   Begin VB.Label Label10 
      Alignment       =   1  'Right Justify
      Caption         =   "איש הקשר:"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   177
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   7440
      TabIndex        =   23
      Top             =   3960
      Width           =   1215
   End
   Begin VB.Label Label11 
      Alignment       =   1  'Right Justify
      Caption         =   "מייל:"
      Height          =   255
      Left            =   7440
      TabIndex        =   22
      Top             =   4560
      Width           =   1215
   End
   Begin VB.Label Label12 
      Alignment       =   1  'Right Justify
      Caption         =   "טלפון 1:"
      Height          =   255
      Left            =   7440
      TabIndex        =   21
      Top             =   5040
      Width           =   1215
   End
   Begin VB.Label Label13 
      Alignment       =   1  'Right Justify
      Caption         =   "טלפון 2:"
      Height          =   255
      Left            =   4320
      TabIndex        =   20
      Top             =   5040
      Width           =   1215
   End
   Begin VB.Label Label14 
      Alignment       =   1  'Right Justify
      Caption         =   "פקס:"
      Height          =   255
      Left            =   1680
      TabIndex        =   19
      Top             =   5040
      Width           =   1215
   End
   Begin VB.Label Label15 
      Alignment       =   1  'Right Justify
      Caption         =   "כרטיס אשראי:"
      Height          =   255
      Left            =   7440
      TabIndex        =   18
      Top             =   5520
      Width           =   1215
   End
   Begin VB.Label Label16 
      Alignment       =   1  'Right Justify
      Caption         =   "תוקף:"
      Height          =   255
      Left            =   4080
      TabIndex        =   17
      Top             =   5520
      Width           =   1215
   End
End
Attribute VB_Name = "frmUpdateCustomer"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Const MOD_NAME = "frmUpdateCustomer."

Private Sub cmdCancel_Click()
10    On Error Resume Next
20        Unload Me
End Sub

Private Sub cmdOK_Click()
Const FUNC_NAME = MOD_NAME & "cmdOK_Click"
10    On Error GoTo func_err
    
    Dim iCustomersID As Long
    
    Dim objCaspit As CaspitAPI.Caspit
    Dim strForeignKey As String
    Dim V As Variant
    Dim iListsID As Long
    
20        V = Split(lstCustomers.List(lstCustomers.ListIndex), "-")
30        strForeignKey = V(UBound(V))
    
    Dim iBankID As Long
40        iBankID = Split(lstBanks.Text, "-")(0)
    
50        If Len(txtBusinessName) = 0 Then
60              MyErrMsgBox "חובה למלא את שם העסק"
70              Exit Sub
80        End If
    
90        If Len(Trim(strForeignKey)) = 0 Then
100     MyErrMsgBox "לא ניתן לבחור בלקוח זה משום שאין לו מפתח זר"
110     Exit Sub
120       End If
    
    'Create the customer
130       Set objCaspit = New CaspitAPI.Caspit
140       With objCaspit
150           .CaspitPath = g_strCaspitPath
160           .AccessPath = g_strAccessPath
170           .BusinessID = g_iBusinessID
180           .DebugMode = g_blnDebug
190       End With
    
200       iCustomersID = objCaspit.UpdateCustomerByForeignKey(txtBusinessName, txtOsekMorshe, _
            txtContactFirstName, txtContactLastName, _
            strForeignKey, _
            txtAddress1, txtAddress2, txtCity, txtPostalCode, _
            txtPhone1, txtPhone2, txtFax, txtEMail, _
            txtAccountNumber, txtBankBranch, iBankID, _
            lstPriceListNum.ItemData(lstPriceListNum.ListIndex), CCur("0" & txtCharge), lstCurrency)
    
210       MyMsgBox "הלקוח עודכן בהצלחה. שם הלקוח: " & txtBusinessName & ". "
    
220       Set objCaspit = Nothing
230   Exit Sub

func_err:
240       Set objCaspit = Nothing
250       MyErrMsgBox "Error " & Err.Number & " in " & FUNC_NAME & "[" & Erl & "]" & "\" & Err.Source & ": " & Err.Description
End Sub
Private Sub Form_Load()
      Const FUNC_NAME = MOD_NAME & "Form_Load"
10    On Error GoTo func_err

20        PopulateCustomers
          
30        PopulatePriceList
          
40    Exit Sub

func_err:
50        MyErrMsgBox "Error " & Err.Number & " in " & FUNC_NAME & "[" & Erl & "]" & "\" & Err.Source & ": " & Err.Description
60        Unload Me
End Sub
Private Sub PopulateCustomers()
Const FUNC_NAME = MOD_NAME & "PopulateCustomers"
10    On Error GoTo func_err
    
    Dim V As Variant
    Dim I As Long
    
    Dim objCaspit As CaspitAPI.Caspit
    Dim objCustomer As CaspitAPI.Customer
    
20        Set objCaspit = New CaspitAPI.Caspit
    
30        With objCaspit
40            .CaspitPath = g_strCaspitPath
50            .AccessPath = g_strAccessPath
60            .BusinessID = g_iBusinessID
70            .DebugMode = g_blnDebug
80        End With
    
90        V = objCaspit.GetCustomers()
    
100       Set objCaspit = Nothing
    
110       If IsEmpty(V) Then
120             Err.Raise 1040, "", "יש ליצור לקוחות לפני שניתן לעדכן אותם"
130       End If
    
140       If UBound(V) < 0 Then
150             Err.Raise 1040, "", "יש ליצור לקוחות לפני שיוצרים חשבונית"
160       End If
    
    'Skip לקוח מזדמן
170       For I = 0 To UBound(V)
180         Set objCustomer = V(I)
190         Call lstCustomers.AddItem(objCustomer.BusinessName & " - " & objCustomer.ForeignKey)
200       Next


210   Exit Sub

func_err:
220       Set objCaspit = Nothing
230       Err.Raise Err.Number, FUNC_NAME & "[" & Erl & "]" & "\" & Err.Source, Err.Description
End Sub

Private Sub lstCustomers_Click()
      Const FUNC_NAME = MOD_NAME & "lstCustomers_Click"

10    On Error GoTo func_err
          Dim objCaspit As CaspitAPI.Caspit
          Dim objCustomer As CaspitAPI.Customer
          Dim strForeignKey As String
          Dim V
          
20        Set objCaspit = New CaspitAPI.Caspit
          
30        With objCaspit
40            .CaspitPath = g_strCaspitPath
50            .AccessPath = g_strAccessPath
60            .BusinessID = g_iBusinessID
70            .DebugMode = g_blnDebug
80        End With
          
          
90        If lstCustomers.ListIndex < 0 Then
100           MyErrMsgBox "חובה לבחור בלקוח"
110           Exit Sub
120       End If
          
130       V = Split(lstCustomers.List(lstCustomers.ListIndex), "-")
140       strForeignKey = Trim(V(UBound(V)))
          
150       If Len(strForeignKey) = 0 Then
160           txtBusinessName = ""
170           txtOsekMorshe = ""
180           txtAddress1 = ""
190           txtAddress2 = ""
200           txtCity = ""
210           txtPostalCode = ""
220           txtContactFirstName = ""
230           txtContactLastName = ""
240           txtEMail = ""
250           txtPhone1 = ""
260           txtPhone2 = ""
270           txtFax = ""
280           txtCreditCard = ""
290           lstExpMonth = ""
300           lstExpYear = ""
310           txtForeignKey = ""
320           txtBankBranch = ""
330           txtAccountNumber = ""
              
340           MyErrMsgBox "לא ניתן לבחור בלקוח זה משום שאין לו מפתח זר"
350           Exit Sub
360       End If
          
370       Set objCustomer = objCaspit.GetCustomerByForeignKey(strForeignKey)
          
380       With objCustomer
390           txtBusinessName = .BusinessName
400           txtOsekMorshe = .OsekMorshe
410           txtAddress1 = .Address1
420           txtAddress2 = .Address2
430           txtCity = .City
440           txtPostalCode = .PostalCode
450           txtContactFirstName = .ContactFirstName
460           txtContactLastName = .ContactLastName
470           txtEMail = .EMail
480           txtPhone1 = .Phone1
490           txtPhone2 = .Phone2
500           txtFax = .Fax
510           txtForeignKey = .ForeignKey
520           txtAccountNumber = .BankAccountNumber
530           txtBankBranch = .BankBranchNumber
540           Call SetBank(lstBanks, .BankID)
550           txtCharge = .Charge
560           SetListBox lstCurrency, .ChargeCurrency
570           SetListBox lstPriceListNum, .PriceListNum
580       End With
          
590       txtCustomerBalance = objCaspit.GetCustomerBalanceByForeignKey(strForeignKey)
          
600       Set objCaspit = Nothing
610   Exit Sub

func_err:
620       Set objCaspit = Nothing
    MyErrMsgBox "Error " & Err.Number & " in " & FUNC_NAME & "[" & Erl & "]" & "\" & Err.Source & ": " & Err.Description
End Sub
Sub SetBank(lstBanks As ComboBox, iBankID As Long)
      Const FUNC_NAME = MOD_NAME & "SetBank"

10    On Error GoTo func_err

          Dim I As Long
          
20        For I = 0 To lstBanks.ListCount - 1
30            If InStr(lstBanks.List(I), iBankID & "-") Then
40                lstBanks.ListIndex = I
50                Exit Sub
60            End If
70        Next
80    Exit Sub

func_err:
90        Err.Raise Err.Number, FUNC_NAME & "[" & Erl & "]" & "\" & Err.Source, Err.Description
End Sub
Sub SetListBox(lstBox As ComboBox, V As Variant)
      Const FUNC_NAME = MOD_NAME & "SetListBox"

10    On Error GoTo func_err

          Dim I As Long
          
20        For I = 0 To lstBox.ListCount - 1
30            If lstBox.List(I) = V Or lstBox.ItemData(I) = V Then
40                lstBox.ListIndex = I
50                Exit Sub
60            End If
70        Next
80    Exit Sub

func_err:
90        Err.Raise Err.Number, FUNC_NAME & "[" & Erl & "]" & "\" & Err.Source, Err.Description
End Sub

Sub PopulatePriceList()
      Const FUNC_NAME = MOD_NAME & "PopulatePriceList"
10    On Error GoTo func_err
        Dim V1
        Dim objCaspit As CaspitAPI.Caspit
        Dim objPriceList As CaspitAPI.PriceList
        Dim I As Long
          
20        Set objCaspit = New CaspitAPI.Caspit
          
30        With objCaspit
40            .CaspitPath = g_strCaspitPath
50            .AccessPath = g_strAccessPath
60            .BusinessID = g_iBusinessID
70            .DebugMode = g_blnDebug
80        End With
        
90        V1 = objCaspit.GetPriceLists()
          
100       For I = 0 To UBound(V1)
110             Set objPriceList = V1(I)
120             lstPriceListNum.AddItem objPriceList.ListID & "-" & Abs(objPriceList.ListNum Mod 10000), I
130             lstPriceListNum.ItemData(I) = objPriceList.ListID

140       Next
          
150       Set objCaspit = Nothing
160   Exit Sub

func_err:
170       Set objCaspit = Nothing
180       Err.Raise Err.Number, FUNC_NAME & "[" & Erl & "]" & "\" & Err.Source, Err.Description
End Sub
